
package codegen
{	
	class SyntaxTree(root : SyntaxNode) 
	{
	  protected var allCommands = "";
	   
	  protected def Traverse() : Unit = 
	  {
	    allCommands = "";
	    Traverse(root);
	  }
	  
	  // preorder traversal
	  protected def Traverse(node : SyntaxNode) : Unit =
	  {
	    allCommands+=node.getCommand();
	    
	    if (node.isRoot)
	    {
		    for(child <- node.asInstanceOf[RootSyntaxNode].smartChildren)
		    	Traverse(child);
	    }
	    else
	    {
	        for(child <- node.children)
		    	Traverse(child);
	    }
	  }

	  // returns the string representation of the program represented by the tree.
	  def getCommands() : String = 
	  {
	    Traverse();
	    allCommands;
	  }
	}
}